\documentclass{article}
\usepackage{pythontex}

\begin{document}

\begin{pycode}
    print(r'\begin{center}')
    print(r'\textit{A message from Python!}')
    print(r'\end{center}')
\end{pycode}

\end{document}
